package com.castle.pdftools.utils;


import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import io.minio.MinioClient;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.UUID;

/**
 * 文件上传工具
 * @author  Dawn
 */
@Configuration
@Slf4j
public class MinioConfiguration {
    @Value("${spring.minio.url}")
    private String url;
    @Value("${spring.minio.accessKey}")
    private String accessKey;
    @Value("${spring.minio.secretKey}")
    private String secretKey;

    @Bean
    public MinioClient minioClient(){
        try {

            MinioClient minioClient = new MinioClient(url, accessKey, secretKey);
            log.info("minioClient初始化完成-----------");
            return minioClient;
        } catch (InvalidEndpointException e) {
            e.printStackTrace();
            log.error("minio初始化失败");
        } catch (InvalidPortException e) {
            e.printStackTrace();
            log.error("minio初始化失败");
        }
       throw new RuntimeException("minio初始化失败");
    }
}
